package com.mes.biz.service.impl;

import com.github.pagehelper.PageInfo;
import com.mes.biz.domain.BizProcessUser;
import com.mes.biz.mapper.BizProcessUserMapper;
import com.mes.biz.service.BizProcessUserService;
import com.mes.common.core.domain.BaseEntity;
import com.mes.common.core.service.BaseServiceImpl;
import com.mes.common.utils.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 工序人员Service业务层处理
 * @author hwg
 * @email hwg
 * @date 2023-04-27
 */
@Service
@Transactional(readOnly = true)
public class BizProcessUserServiceImpl extends BaseServiceImpl<BizProcessUserMapper, BizProcessUser> implements BizProcessUserService {

    private static final Logger log = LoggerFactory.getLogger(BizProcessUserServiceImpl.class);

    /**
     * 获取单条数据
     * @param bizProcessUser 工序人员
     * @return 工序人员
     */
    @Override
    public BizProcessUser get(BizProcessUser bizProcessUser) {
        BizProcessUser dto = super.get(bizProcessUser);
        return dto;
    }

    /**
     * 获取单条数据
     * @param id 工序人员id
     * @return 工序人员
     */
    @Override
    public BizProcessUser get(String id) {
        BizProcessUser dto = super.get(id);
        return dto;
    }

    /**
     * 查询工序人员列表
     * @param bizProcessUser 工序人员
     * @return 工序人员
     */
    @Override
    public List<BizProcessUser> findList(BizProcessUser bizProcessUser) {
		List<BizProcessUser> bizProcessUserList = super.findList(bizProcessUser);
        return bizProcessUserList;
    }

    /**
     * 分页查询工序人员列表
     * @param bizProcessUser 工序人员
     * @return 工序人员
     */
    @Override
    public PageInfo<BizProcessUser> findPage(BizProcessUser bizProcessUser) {
		PageInfo<BizProcessUser> page = super.findPage(bizProcessUser);
        return page;
    }

    /**
     * 保存工序人员
     * @param bizProcessUser
     * @return 结果
     */
    @Override
    public boolean save(BizProcessUser bizProcessUser) {
        return super.save(bizProcessUser);
    }

    /**
     * 删除工序人员信息
     * @param bizProcessUser
     * @return 结果
     */
    @Override
    public boolean remove(BizProcessUser bizProcessUser) {
        return super.remove(bizProcessUser);
    }

    /**
     * 批量删除工序人员
     * @param ids 需要删除的工序人员ID
     * @return 结果
     */
    @Transactional(readOnly = false)
    @Override
    public int deleteBizProcessUserByIds(String[] ids) {
        return mapper.deleteBizProcessUserByIds(ids, BaseEntity.DEL_FLAG_DELETE);
    }

    @Override
    @Transactional
    public boolean saveBatch(List<BizProcessUser> bizProcessUserList) {
        //删除工序人员
        String processId = bizProcessUserList.get(0).getProcessId();
//        mapper.deleteByProducessId(processId, BaseEntity.DEL_FLAG_DELETE);
        for(BizProcessUser bizProcessUser:bizProcessUserList) {
            bizProcessUser.setTenantId(SecurityUtils.getTenantId());
            bizProcessUser.preInsert();
        }
        //新增工序人员
        int result = mapper.saveBatch(bizProcessUserList);
        return result>0;
    }

    @Override
    public boolean findInfoByUserId(String userId, String processId) {

        return mapper.findInfoByUserId(userId, processId) > 0;
    }

    @Override
    public List<BizProcessUser> getListByUserId(String userId) {
        return mapper.getListByUserId(userId);
    }

}
